package com.uwaterloo.jobmineplus;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.uwaterloo.jobmineplus.backend.Authentication;
import com.uwaterloo.jobmineplus.mock.MockAuthentication;

public class Main extends Activity {
	private static final Authentication AUTH = new MockAuthentication();
	private static final String ERR_MSG = "Authentication Fail. Please input the right username and password";
    
	private EditText uwUserIdInputBox;
    private EditText uwPasswordInputBox;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        uwUserIdInputBox = (EditText)findViewById(R.id.uwUserIdEntry);
        uwPasswordInputBox = (EditText)findViewById(R.id.uwPasswordEntry);
        
        final Button loginButton = (Button)findViewById(R.id.loginLabel);
        loginButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				onLoginButtonClicked();
				
			}
		});
    }
    
    private void onLoginButtonClicked() {
    	String uwUserId = uwUserIdInputBox.getText().toString();
    	String uwPassword = uwPasswordInputBox.getText().toString();
		
    	if(AUTH.isValiatedUser(uwUserId, uwPassword)) {
    		Intent intent = new Intent(this, InterviewTab.class);
    		startActivity(intent);
    	}
    	else {
    		displayLoginErrorMsg();
    	}
    }
    
    private void displayLoginErrorMsg(){
    	final TextView textView= (TextView)findViewById(R.id.loginErrorMsg);
    	textView.setText(ERR_MSG);
    }
}